//
//  ZQQrResultPage.m
//  jianzhik
//
//  Created by huami on 2018/9/1.
//  Copyright © 2018年 WKWebView. All rights reserved.
//
#import "ZQProcessedOrderPage.h"
#import "ZQQrResultPage.h"
#import "ZQMainPage.h"
@interface ZQQrResultPage ()
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;

@end

@implementation ZQQrResultPage

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"广播交易";
    self.contentLabel.text = self.resultContent;
}

- (IBAction)tradingClick:(id)sender {
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    NSString *url = @"/v1/work/sendsigned";
    
    if (self.zzModel) {
        url = @"/v1/active/sendsigned";
        parameters[@"Signed"] = self.resultContent;
        parameters[@"Symbol"] = self.zzModel.bzType;
        parameters[@"To"] = self.zzModel.to;
    } else {
        parameters[@"Id"] = self.penModel.Id;
        parameters[@"Signed"] = self.resultContent;
    }
    
    [ZQAFHelper afnetworkRequestWithPostURL:url  parameters:parameters view:self.view finishedBlcok:^(NSDictionary *dict) {
        [self pushWhere];
    }];
}

/**
 根据管理员名字判断跳转还是返回到主页，超级c管理员没有已处理订单模块
*/
- (void)pushWhere
{
    NSString *superName = [[NSUserDefaults standardUserDefaults] objectForKey:@"Username"];

    [UIHelper showSuccessMessage:@"广播成功" afterHideHud:2 toView:self.view completion:^{
        if ([superName isEqualToString:@"admin"]) {
            for (UIViewController *controller in self.navigationController.viewControllers) {
                if ([controller isKindOfClass:[ZQMainPage class]]) {
                    ZQMainPage *vc =(ZQMainPage *)controller;
                    [self.navigationController popToViewController:vc animated:YES];
                    [UIHelper showSuccessMessage:@"交易完成!" afterHideHud:2 toView:vc.view completion:nil];
                }
            }
        } else{
             // 跳转到已处理订单界面
            ZQProcessedOrderPage *vc = [ZQProcessedOrderPage new];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }];
}
@end
